package com.xfly.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ptmall.app.R;
import com.ptmall.app.utils.GlideUtil;
import com.xfly.app.bean.BankBean;
import com.xfly.app.bean.KcBean;

import java.util.List;


/**
 * Created by Administrator on 2018/1/12.
 */



public class SubGoodAdapter extends BaseAdapter {

    private Context mContext;
    private List<KcBean> mDataList;
    private LayoutInflater mLayoutInflater;

    public SubGoodAdapter(Context context, List<KcBean> list) {
        this.mContext = context;
        this.mDataList = list;
        this.mLayoutInflater = LayoutInflater.from(mContext);
    }

    public void pushData(List<KcBean> list){
        this.mDataList = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if(mDataList == null){
            return 0;
        }
        return mDataList.size();
    }

    Click click;

    public void setClick(Click click){
        this.click = click;
    }


    @Override
    public Object getItem(int position) {
        return mDataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (null == convertView) {
            convertView = mLayoutInflater.inflate(R.layout.item_subgood, parent,false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        KcBean bean = mDataList.get(position);

        GlideUtil.showImg(mContext,bean.cover+"",viewHolder.img);
        viewHolder.goodname.setText(bean.name);

        viewHolder.jia.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                click.Click(position);
            }
        });

        viewHolder.goodnum.setText(bean.num);

        viewHolder.jian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                click.Click2(position);
            }
        });

        return convertView;
    }

    class ViewHolder {

        TextView goodname,goodnum;
        ImageView img,jia,jian;

        ViewHolder(View view) {
            goodname = (TextView) view.findViewById(R.id.goodname);
            img = (ImageView) view.findViewById(R.id.img);
            jia = (ImageView) view.findViewById(R.id.jia);
            jian = (ImageView) view.findViewById(R.id.jian);
            goodnum = view.findViewById(R.id.goodnum);
        }
    }

    public  interface Click{
        void Click(int position);
        void Click2(int position);
    }

}
